package com.lx.inter.condition;

import com.lx.constant.ano.FieldFunction;
import com.lx.wrapper.AbstractCommonConditionWrapper;

import java.util.Collection;

/**
 * 主实体定义条件项,所有条件仅能在主实体类下补全
 * 如需任意实体都能补全条件,请参考 {@link IEveryEntityLambdaDefineCondition}
 * 本接口实现类
 *
 * @param <MainEntity>
 * @author lx
 * @create 2023/2/24 23:46
 **/
public interface IMainEntityLambdaDefineCondition<MainEntity, ChildWrapper extends AbstractCommonConditionWrapper> {

    /**
     * 相等 条件
     *
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public default ChildWrapper eq(FieldFunction<MainEntity, ?> conditionColFn, Object val) {
        return eq(true, conditionColFn, val);
    }

    /**
     * 相等 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public ChildWrapper eq(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object val);

    /**
     * 相等 条件
     *
     * @param conditionColFn   Lambda属性项
     * @param conditionWrapper 条件子项
     * @return
     */
    public default ChildWrapper eq(FieldFunction<MainEntity, ?> conditionColFn, AbstractCommonConditionWrapper conditionWrapper) {
        return eq(true, conditionColFn, conditionWrapper);
    }

    /**
     * 相等 条件
     *
     * @param condition        查询条件,true=执行查询 false-中止查询
     * @param conditionColFn   Lambda属性项
     * @param conditionWrapper 条件子项
     * @return
     */
    public ChildWrapper eq(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, AbstractCommonConditionWrapper conditionWrapper);

    /**
     * 相等 条件 主实体类和任意一个实体类属性组合,支持子查询语句嵌套
     *
     * @param columnColFn      其他实体对应的条件属性列（本列支持Hibernate特殊解析）
     * @param conditionFieldFn 其他实体对应的条件属性列 注意:本列暂不支持Hibernate特殊解析,例: [user]属性 无法解析为[user.id]
     * @param <EveryEntity>
     * @return
     */
    public default <EveryEntity> ChildWrapper eq(FieldFunction<MainEntity, ?> columnColFn, FieldFunction<EveryEntity, ?> conditionFieldFn) {
        return eq(true, columnColFn, conditionFieldFn);
    }

    /**
     * 相等 条件 主实体类和任意一个实体类属性组合,支持子查询语句嵌套
     *
     * @param columnColFn
     * @param conditionFieldFn
     * @param <EveryEntity>
     * @return
     */
    public <EveryEntity> ChildWrapper eq(boolean condition, FieldFunction<MainEntity, ?> columnColFn, FieldFunction<EveryEntity, ?> conditionFieldFn);

    /**
     * 不等 条件
     *
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public default ChildWrapper ne(FieldFunction<MainEntity, ?> conditionColFn, Object val) {
        return ne(true, conditionColFn, val);
    }

    /**
     * 不等 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public ChildWrapper ne(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object val);

    /**
     * 不等 条件
     *
     * @param conditionColFn   Lambda属性项
     * @param conditionWrapper 条件子项
     * @return
     */
    public default ChildWrapper ne(FieldFunction<MainEntity, ?> conditionColFn, AbstractCommonConditionWrapper conditionWrapper) {
        return ne(true, conditionColFn, conditionWrapper);
    }

    /**
     * 不等 条件
     *
     * @param condition        查询条件,true=执行查询 false-中止查询
     * @param conditionColFn   Lambda属性项
     * @param conditionWrapper 条件子项
     * @return
     */
    public ChildWrapper ne(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, AbstractCommonConditionWrapper conditionWrapper);

    /**
     * 大于 条件
     *
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public default ChildWrapper gt(FieldFunction<MainEntity, ?> conditionColFn, Object val) {
        return gt(true, conditionColFn, val);
    }

    /**
     * 大于 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public ChildWrapper gt(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object val);

    /**
     * 大于等于 条件
     *
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public default ChildWrapper ge(FieldFunction<MainEntity, ?> conditionColFn, Object val) {
        return ge(true, conditionColFn, val);
    }

    /**
     * 大于等于 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public ChildWrapper ge(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object val);

    /**
     * 小于 条件
     *
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public default ChildWrapper lt(FieldFunction<MainEntity, ?> conditionColFn, Object val) {
        return lt(true, conditionColFn, val);
    }

    /**
     * 小于 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public ChildWrapper lt(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object val);

    /**
     * 小于等于 条件
     *
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public default ChildWrapper le(FieldFunction<MainEntity, ?> conditionColFn, Object val) {
        return le(true, conditionColFn, val);
    }

    /**
     * 小于等于 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param val            查询值项
     * @return
     */
    public ChildWrapper le(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object val);

    /**
     * in 条件
     *
     * @param conditionColFn Lambda属性项
     * @param valArr
     * @return
     */
    public default ChildWrapper in(FieldFunction<MainEntity, ?> conditionColFn, Object... valArr) {
        return in(true, conditionColFn, valArr);
    }

    /**
     * in 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param valArr
     * @return
     */
    public ChildWrapper in(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object... valArr);

    /**
     * in 条件
     *
     * @param conditionColFn Lambda属性项
     * @param valCol         数据集合
     * @return
     */
    public default ChildWrapper in(FieldFunction<MainEntity, ?> conditionColFn, Collection<?> valCol) {
        return in(true, conditionColFn, valCol);
    }

    /**
     * in 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param valCol         数据集合
     * @return
     */
    public default ChildWrapper in(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Collection<?> valCol) {
        return in(condition, conditionColFn, valCol == null ? null : valCol.toArray());
    }

    /**
     * in 条件
     *
     * @param conditionColFn Lambda属性项
     * @param childWrapper   子条件项
     * @return
     */
    public default ChildWrapper in(FieldFunction<MainEntity, ?> conditionColFn, AbstractCommonConditionWrapper childWrapper) {
        return in(true, conditionColFn, childWrapper);
    }

    /**
     * in 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param childWrapper   子条件项
     * @return
     */
    public ChildWrapper in(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, AbstractCommonConditionWrapper childWrapper);

    /**
     * not in 条件
     *
     * @param conditionColFn Lambda属性项
     * @param valArr
     * @return
     */
    public default ChildWrapper notIn(FieldFunction<MainEntity, ?> conditionColFn, Object... valArr) {
        return notIn(true, conditionColFn, valArr);
    }

    /**
     * not in 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param valArr
     * @return
     */
    public ChildWrapper notIn(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object... valArr);

    /**
     * not in 条件
     *
     * @param conditionColFn Lambda属性项
     * @param valCol         数据集合
     * @return
     */
    public default ChildWrapper notIn(FieldFunction<MainEntity, ?> conditionColFn, Collection<?> valCol) {
        return notIn(true, conditionColFn, valCol);
    }

    /**
     * not in 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param valCol         数据集合
     * @return
     */
    public default ChildWrapper notIn(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Collection<?> valCol) {
        return notIn(condition, conditionColFn, valCol == null ? null : valCol.toArray());
    }

    /**
     * not in 条件
     *
     * @param conditionColFn Lambda属性项
     * @param childWrapper   子条件项
     * @return
     */
    public default ChildWrapper notIn(FieldFunction<MainEntity, ?> conditionColFn, AbstractCommonConditionWrapper childWrapper) {
        return notIn(true, conditionColFn, childWrapper);
    }

    /**
     * not in 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param childWrapper   子条件项
     * @return
     */
    public ChildWrapper notIn(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, AbstractCommonConditionWrapper childWrapper);

    /**
     * 自定义 Like 条件
     *
     * @param conditionColFn Lambda属性项
     * @param val
     * @return
     */
    public default ChildWrapper like(FieldFunction<MainEntity, ?> conditionColFn, Object val) {
        return like(true, conditionColFn, val);
    }

    /**
     * 自定义 Like 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param val
     * @return
     */
    public ChildWrapper like(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object val);

    /**
     * 左模糊查询条件
     *
     * @param conditionColFn Lambda属性项
     * @param val
     * @return
     */
    public default ChildWrapper likeLeft(FieldFunction<MainEntity, ?> conditionColFn, Object val) {
        return likeLeft(true, conditionColFn, val);
    }

    /**
     * 左模糊查询条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param val
     * @return
     */
    public ChildWrapper likeLeft(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object val);

    /**
     * 右模糊查询条件(可能存在性能问题)
     *
     * @param conditionColFn Lambda属性项
     * @param val
     * @return
     */
    public default ChildWrapper likeRight(FieldFunction<MainEntity, ?> conditionColFn, Object val) {
        return likeRight(true, conditionColFn, val);
    }

    /**
     * 右模糊查询条件(可能存在性能问题)
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @param val
     * @return
     */
    public ChildWrapper likeRight(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object val);

    /**
     * IS NULL 条件
     *
     * @param conditionColFn Lambda属性项
     * @return
     */
    public default ChildWrapper isNull(FieldFunction<MainEntity, ?> conditionColFn) {
        return isNull(true, conditionColFn);
    }

    /**
     * IS NULL 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @return
     */
    public ChildWrapper isNull(boolean condition, FieldFunction<MainEntity, ?> conditionColFn);

    /**
     * IS NOT NULL 条件
     *
     * @param conditionColFn Lambda属性项
     * @return
     */
    public default ChildWrapper isNotNull(FieldFunction<MainEntity, ?> conditionColFn) {
        return isNotNull(true, conditionColFn);
    }

    /**
     * IS NOT NULL 条件
     *
     * @param condition      查询条件,true=执行查询 false-中止查询
     * @param conditionColFn Lambda属性项
     * @return
     */
    public ChildWrapper isNotNull(boolean condition, FieldFunction<MainEntity, ?> conditionColFn);

    /**
     * Between and 条件
     *
     * @param conditionColFn
     * @param startVal       查询开始值
     * @param endVal         查询结束值
     * @return
     */
    public default ChildWrapper between(FieldFunction<MainEntity, ?> conditionColFn, Object startVal, Object endVal) {
        return between(true, conditionColFn, startVal, endVal);
    }

    /**
     * Between and 条件
     *
     * @param condition
     * @param conditionColFn
     * @param startVal       查询开始值
     * @param endVal         查询结束值
     * @return
     */
    public ChildWrapper between(boolean condition, FieldFunction<MainEntity, ?> conditionColFn, Object startVal, Object endVal);
}
